import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class MyDialog extends Dialog {
  final String title;
  final String content;
  final String okBtn;

  //取消
  final String cancelBtn;

  //确定
  final Function okCallback;

  const MyDialog({
    super.key,
    required this.title,
    required this.content,
    this.okBtn = "确定",
    this.cancelBtn = "取消",
    required this.okCallback,
  });

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Center(
        child: Container(
          width: 300,
          height: 300,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            color: Colors.white,
          ),
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.fromLTRB(10, 0, 0, 0),
                child: Stack(
                  children: [
                    Center(
                      child: Container(
                        alignment: Alignment.center,
                        height: 45,
                        child: Text(
                          title,
                          style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                        ),
                      ),
                    ),
                    Align(
                      alignment: Alignment.topRight,
                      child: Container(
                        width: 45,
                        height: 45,
                        child: GestureDetector(
                          child: const Icon(
                            Icons.close,
                            size: 30,
                          ),
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                        ),
                      ),
                    )
                  ],
                ),
              ),
              const Divider(
                height: 1,
              ),
              IntrinsicHeight(
                child: Container(
                  alignment: Alignment.center,
                  height: 203,
                  child: Text(content),
                ),
              ),
              const Divider(
                height: 1,
              ),
              Row(
                children: [
                  Expanded(
                      child: GestureDetector(
                          child: Container(
                            alignment: Alignment.center,
                            height: 50,
                            color: Colors.transparent,
                            child: Text(
                              cancelBtn,
                              style: const TextStyle(color: Colors.black),
                            ),
                          ),
                          onTap: () {
                            Navigator.of(context).pop();
                            Fluttertoast.showToast(msg: "点击取消");
                          })),
                  Container(
                    width: 1,
                    height: 50,
                    color: Colors.purple,
                  ),
                  Expanded(
                      child: GestureDetector(
                    child: Container(
                      alignment: Alignment.center,
                      height: 50,
                      decoration: const BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.only(bottomRight: Radius.circular(10))),
                      child: Text(
                        okBtn,
                        style: TextStyle(color: Colors.white),
                      ),
                    ),
                    onTap: () {
                      Navigator.of(context).pop();
                      okCallback();
                    },
                  )),
                ],
              )
            ],
          ),
        ),
      ),
    );
  }
}
